var app = require('express')()
var http = require('http').Server(app)
var io = require('socket.io')(http)

app.get('/', (req, res) => {
  // res.send('<h1>Hello Socket</h1>')
  res.sendFile(__dirname + '/index.html')
})

// io.on('connection', socket => {
//   console.log('a user is conneted')
//   socket.on('disconnect', () => {
//     console.log('user is disconnected')
//   })
// })

io.on('connection', function(socket) {
  socket.on('chat message', function(msg) {
    console.log('message:' + msg)
    io.emit('chat message', msg)
  })
})

http.listen(3000, () => {
  console.log('running ...')
})